<template>
  <div class="login-container">
    <div class="login-box">
      <h2>登录</h2>
      <el-form :model="form" ref="formRef" @keyup.enter="handleLogin">
        <el-form-item prop="username">
          <el-input v-model="form.username" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" type="password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin" style="width:100%">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()
const form = ref({ username: '', password: '' })
const formRef = ref(null)

const handleLogin = () => {
  if (form.value.username === 'demo' && form.value.password === '123456') {
    localStorage.setItem('isLogin', '1')
    localStorage.setItem('username', form.value.username)
    ElMessage.success('登录成功')
    router.replace('/')
  } else {
    ElMessage.error('账号或密码错误')
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0e7ff 0%, #f0f8ff 100%);
}
.login-box {
  background: #fff;
  padding: 40px 32px 32px 32px;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  min-width: 320px;
}
.login-box h2 {
  text-align: center;
  color: #409eff;
  margin-bottom: 30px;
}
</style> 